package com.elh.serurity.service;

import com.elh.serurity.dao.UsersMapper;
import com.elh.serurity.model.Users;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;


/**
 * @author liulei
 */
@Service
public class MyUserDetailService implements UserDetailsService {

    @Autowired
    private UsersMapper usersMapper;

    @Autowired
    private PasswordEncoder passwordEncoder;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        Users users = new Users();
        if (users == null) {
            throw new UsernameNotFoundException("账户不存在!");
        }
        users.setUsername("admin");
        users.setPassword("123");
//        List<Role> userRoles = usersMapper.getUserRolesByUid(users.getId());
//        users.setUserRoles(userRoles);
        users.setLoginTime(System.currentTimeMillis());
        return users;
    }



}
